class CulturalHeritage::ShapesController < ApplicationController
  #before_filter :authenticate_user!
  # GET /cultural_heritage/shapes
  # GET /cultural_heritage/shapes.xml
  def index
    @title_view = 'Formas'
    @cultural_heritage_shapes = CulturalHeritage::Shape.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @cultural_heritage_shapes }
    end
  end

  # GET /cultural_heritage/shapes/1
  # GET /cultural_heritage/shapes/1.xml
  def show
    @cultural_heritage_shape = CulturalHeritage::Shape.find(params[:id])
    @title_view = 'Formas'
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @cultural_heritage_shape }
    end
  end

  # GET /cultural_heritage/shapes/new
  # GET /cultural_heritage/shapes/new.xml
  def new
    if (user_signed_in? && ([2].include?(current_user.role)))
    @cultural_heritage_shape = CulturalHeritage::Shape.new
    @title_view = 'Formas'
    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @cultural_heritage_shape }
    end
    else
      respond_to do |format|
        format.html { redirect_to(new_user_session_path) }
      end
    end
  end

  # GET /cultural_heritage/shapes/1/edit
  def edit
    if (user_signed_in? && ([2].include?(current_user.role)))
    @cultural_heritage_shape = CulturalHeritage::Shape.find(params[:id])
    @title_view = 'Formas'
    else
      respond_to do |format|
        format.html { redirect_to(new_user_session_path) }
      end
    end
  end

  # POST /cultural_heritage/shapes
  # POST /cultural_heritage/shapes.xml
  def create
    if (user_signed_in? && ([2].include?(current_user.role)))
    @cultural_heritage_shape = CulturalHeritage::Shape.new(params[:cultural_heritage_shape])
    @title_view = 'Formas'
    respond_to do |format|
      if @cultural_heritage_shape.save
        format.html { redirect_to(@cultural_heritage_shape, :notice => 'Se ha creado correctamente la Forma.') }
        format.xml  { render :xml => @cultural_heritage_shape, :status => :created, :location => @cultural_heritage_shape }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @cultural_heritage_shape.errors, :status => :unprocessable_entity }
      end
    end
    else
      respond_to do |format|
        format.html { redirect_to(new_user_session_path) }
      end
    end
  end

  # PUT /cultural_heritage/shapes/1
  # PUT /cultural_heritage/shapes/1.xml
  def update
    if (user_signed_in? && ([2].include?(current_user.role)))
    @cultural_heritage_shape = CulturalHeritage::Shape.find(params[:id])
    @title_view = 'Formas'
    respond_to do |format|
      if @cultural_heritage_shape.update_attributes(params[:cultural_heritage_shape])
        format.html { redirect_to(@cultural_heritage_shape, :notice => 'Se ha actualizado correctamente la Forma.') }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @cultural_heritage_shape.errors, :status => :unprocessable_entity }
      end
    end
    else
      respond_to do |format|
        format.html { redirect_to(new_user_session_path) }
      end
    end
  end

  # DELETE /cultural_heritage/shapes/1
  # DELETE /cultural_heritage/shapes/1.xml
  def destroy
    if (user_signed_in? && ([2].include?(current_user.role)))
    @cultural_heritage_shape = CulturalHeritage::Shape.find(params[:id])
    mensaje = @cultural_heritage_shape.erasable
    if mensaje.blank?
      @cultural_heritage_shape.deleted = 1
      @cultural_heritage_shape.save
    end
    respond_to do |format|
      format.html { redirect_to(cultural_heritage_shapes_url, :notice => mensaje) }
      format.xml  { head :ok }
    end
    else
      respond_to do |format|
        format.html { redirect_to(new_user_session_path) }
      end
    end
  end
end
